﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_friend : System.Web.UI.Page
{
    AccessDAO dao = new AccessDAO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            show();
        }
    }
    private void show()
    {
        string ss = "select * from friend";
        DataSet ds = dao.getDs(ss);
        this.GridView1.DataSource = ds;
        this.GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        show();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
        string ss = "delete from friend where id="+id;
        if (dao.getComm(ss) != 0)
        {
            RegisterStartupScript("check", "<script language='javascript'>alert('记录已删除');</script>");
            show();
        }
        else
        {
            RegisterStartupScript("check", "<script language='javascript'>alert('对不起，删除失败');</script>");
        }
    }
    //修改
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        this.GridView1.EditIndex = -1;
        show();
    }
 
    protected void GridView1_RowEditing1(object sender, GridViewEditEventArgs e)
    {
        this.GridView1.EditIndex = e.NewEditIndex;
        show();
    }
    protected void GridView1_RowUpdating1(object sender, GridViewUpdateEventArgs e)
    {
        int id = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
        string name = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.ToString();
        string http = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString();

        string ss = "update friend set name='" + name + "',http='" + http + "' where id=" + id;
        if (dao.getComm(ss) != 0)
        {
            this.GridView1.EditIndex = -1;
            show();
            RegisterStartupScript("check", "<script language='javascript'>alert('记录已更新');</script>");
        }
    }
}
